/*
 * Zhz.net Inc.
 * Copyright (c) 2010 All Rights Reserved.
 */
package com.zhz.project.dal.ibatis;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.zhz.project.dal.daointerface.RoleDAO;

// auto generated imports
import com.zhz.project.dal.dataobject.RoleDO;
import org.springframework.dao.DataAccessException;
import java.util.List;
import com.zhz.project.common.util.page.PageList;
import com.zhz.project.dal.dataobject.RoleDO;
import java.util.Map;
import java.util.HashMap;
import com.zhz.project.common.util.page.Paginator;

/**
 * An ibatis based implementation of dao interface <tt>com.zhz.project.dal.daointerface.RoleDAO</tt>.
 *
 * This file is generated by <tt>paygw-dalgen</tt>, a DAL (Data Access Layer)
 * code generation utility specially developed for <tt>paygw</tt> project.
 * 
 * PLEASE DO NOT MODIFY THIS FILE MANUALLY, or else your modification may
 * be OVERWRITTEN by someone else. To modify the file, you should go to 
 * directory <tt>(project-home)/biz/dal/src/conf/dalgen</tt>, and 
 * find the corresponding configuration file (<tt>tables/role.xml</tt>). 
 * Modify the configuration file according to your needs, then run <tt>paygw-dalgen</tt> 
 * to generate this file.
 *
 * @author Li Wei
 */
public class IbatisRoleDAO extends SqlMapClientDaoSupport implements RoleDAO {
	/**
	 *  Query DB table <tt>role</tt> for records.
	 *
   	 *  <p>
   	 *  Description for this operation is<br>
   	 *  <tt></tt>
	 *  <p>
	 *  The sql statement for this operation is <br>
	 *  <tt>select * from role where (id = ?)</tt>
	 *
	 *	@param id
	 *	@return RoleDO
	 *	@throws DataAccessException
	 */	 
    public RoleDO getById(int id) throws DataAccessException {
        Integer param = new Integer(id);

        return (RoleDO) getSqlMapClientTemplate().queryForObject("MS-ROLE-GET-BY-ID", param);

    }

	/**
	 *  Query DB table <tt>role</tt> for records.
	 *
   	 *  <p>
   	 *  Description for this operation is<br>
   	 *  <tt></tt>
	 *  <p>
	 *  The sql statement for this operation is <br>
	 *  <tt>select * from role</tt>
	 *
	 *	@return List<RoleDO>
	 *	@throws DataAccessException
	 */	 
    public List<RoleDO> getAllRole() throws DataAccessException {

        return getSqlMapClientTemplate().queryForList("MS-ROLE-GET-ALL-ROLE", null);

    }

	/**
	 *  Query DB table <tt>role</tt> for records.
	 *
   	 *  <p>
   	 *  Description for this operation is<br>
   	 *  <tt></tt>
	 *  <p>
	 *  The sql statement for this operation is <br>
	 *  <tt>select * from role where (name = '')</tt>
	 *
	 *	@param pageSize
	 *	@param pageNum
	 *	@return PageList
	 *	@throws DataAccessException
	 */	 
    public PageList queryPaging(int pageSize, int pageNum) throws DataAccessException {
        Map param = new HashMap();

        param.put("pageSize", new Integer(pageSize));
        param.put("pageNum", new Integer(pageNum));

        Paginator paginator = new Paginator();
        paginator.setItemsPerPage(pageSize);
        paginator.setPage(pageNum);

        paginator.setItems(((Integer) getSqlMapClientTemplate().queryForObject("MS-ROLE-QUERY-PAGING-COUNT-FOR-PAGING", param)).intValue());
        
        PageList  pageList = new PageList();
        pageList.setPaginator(paginator);
        
        if (paginator.getBeginIndex() <= paginator.getItems()) {
            param.put("startRow", new Integer(paginator.getBeginIndex()));
            param.put("itemsPerPage", new Integer(paginator.getItemsPerPage()));
            pageList.addAll(getSqlMapClientTemplate().queryForList("MS-ROLE-QUERY-PAGING", param));
        }
        
        return pageList;
    }

}